<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>区块链资产管理</title>
    <style>
        :root {
            --primary-color: #007AFF;
            --background-color: #F5F5F7;
            --card-background: #FFFFFF;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell;
            background-color: var(--background-color);
            margin: 0;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
        }

        .card {
            background: var(--card-background);
            border-radius: 18px;
            padding: 24px;
            margin-bottom: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }

        .input-group {
            margin-bottom: 16px;
        }

        input {
            width: 100%;
            padding: 12px;
            border: 1px solid #E0E0E0;
            border-radius: 12px;
            font-size: 16px;
            margin-top: 8px;
        }

        button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            transition: opacity 0.3s;
        }

        button:hover {
            opacity: 0.9;
        }

        .asset-details {
            padding: 20px;
            background: #F8F9FA;
            border-radius: 12px;
            margin-top: 20px;
        }

        h2 {
            color: #1D1D1F;
            margin-bottom: 20px;
        }

        .status {
            padding: 12px;
            border-radius: 8px;
            margin-top: 16px;
            display: none;
        }

        .success {
            background: #D1FAE5;
            color: #065F46;
        }

        .error {
            background: #FEE2E2;
            color: #991B1B;
        }
    </style>
</head>
<body>
    <div id="app" class="container">
        <!-- 创建资产 -->
        <div class="card">
            <h2>创建数字资产</h2>
            <div class="input-group">
                <input v-model="newAsset.id" placeholder="资产ID">
            </div>
            <div class="input-group">
                <input v-model="newAsset.owner" placeholder="所有者">
            </div>
            <div class="input-group">
                <input v-model="newAsset.name" placeholder="资产名称">
            </div>
            <div class="input-group">
                <input v-model="newAsset.info" placeholder="资产信息">
            </div>
            <button @click="createAsset">创建资产</button>
        </div>

        <!-- 查询资产 -->
        <div class="card">
            <h2>查询资产信息</h2>
            <div class="input-group">
                <input v-model="queryId" placeholder="输入资产ID">
            </div>
            <button @click="queryAsset">查询</button>
            <div v-if="assetDetails" class="asset-details">
                <p><strong>所有者:</strong> {{ assetDetails.owner }}</p>
                <p><strong>名称:</strong> {{ assetDetails.name }}</p>
                <p><strong>信息:</strong> {{ assetDetails.info }}</p>
            </div>
        </div>

        <!-- 转移资产 -->
        <div class="card">
            <h2>资产转移</h2>
            <div class="input-group">
                <input v-model="transfer.id" placeholder="资产ID">
            </div>
            <div class="input-group">
                <input v-model="transfer.newOwner" placeholder="新所有者">
            </div>
            <button @click="transferAsset">确认转移</button>
        </div>

        <!-- 状态提示 -->
        <div :class="['status', statusType]" v-if="statusMessage">
            {{ statusMessage }}
        </div>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const { createApp } = Vue;

        createApp({
            data() {
                return {
                    newAsset: { id: '', owner: '', name: '', info: '' },
                    queryId: '',
                    assetDetails: null,
                    transfer: { id: '', newOwner: '' },
                    statusMessage: '',
                    statusType: 'success'
                }
            },
            methods: {
                async createAsset() {
                    try {
                        // 这里替换为实际的API调用
                        const response = await fetch('/api/create', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify(this.newAsset)
                        });
                        
                        this.showStatus('资产创建成功', 'success');
                        this.newAsset = { id: '', owner: '', name: '', info: '' };
                    } catch (error) {
                        this.showStatus('操作失败: ' + error.message, 'error');
                    }
                },

                async queryAsset() {
                    if (!this.queryId) return;
                    
                    try {
                        // 这里替换为实际的API调用
                        const response = await fetch(`/api/query/${this.queryId}`);
                        const data = await response.json();
                        
                        if (data.error) {
                            this.showStatus(data.error, 'error');
                            this.assetDetails = null;
                        } else {
                            this.assetDetails = data;
                        }
                    } catch (error) {
                        this.showStatus('查询失败', 'error');
                    }
                },

                async transferAsset() {
                    try {
                        // 这里替换为实际的API调用
                        const response = await fetch('/api/transfer', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify(this.transfer)
                        });
                        
                        this.showStatus('资产转移成功', 'success');
                        this.transfer = { id: '', newOwner: '' };
                    } catch (error) {
                        this.showStatus('转移失败: ' + error.message, 'error');
                    }
                },

                showStatus(message, type) {
                    this.statusMessage = message;
                    this.statusType = type;
                    setTimeout(() => {
                        this.statusMessage = '';
                    }, 3000);
                }
            }
        }).mount('#app');
    </script>
</body>
</html>